import { Loading } from 'element-ui';
import { Message } from 'element-ui';
import citys from "../assets/citys.json"
import {trace} from "./trace"
var loadingInstance;


export const keyStatusList =
  [
    {
      value: "0",
      label: "关键词状态"
    },
    {
      value: "1",
      label: "已禁用"
    },
    {
      value: "2",
      label: "运行中"
    },
    {
      value: "3",
      label: "已到期"
    },
    {
      value: "4",
      label: "审核未通过"
    }
    ,
    {
      value: "5",
      label: "审核中"
    }
  ]


export const tagStatusList =
{
  1: "info",
  2: "success",
  3: "info",
  4: "danger",
  5: "warning"
}

/**
 * 获取城市列表
 * @returns {Array}
 */
export function getCitys() {
  var options = []
  trace("citys=",citys);
  citys.provinces.map(item=>{
    var child = {
      value: item.provinceName,
      label: item.provinceName,
      children: []
    };
    item.citys.map(m_item=>{
      child.children.push({
        label:m_item.citysName,
        value:m_item.citysName
      })
    })
    options.push(child);
  });

  return options;
}

/**
 * 去除字符串空格
 * @param str
 * @returns {*}
 * @constructor
 */
export function Trim(str)
{
  return str.replace(/(^\s*)|(\s*$)/g, "");
}
// 发票管理状态
export const invoiceStatusList = [
  {
    key: "4",
    type: 'success',
    label: "已开发票"
  },
  {
    key: "5",
    type: 'success',
    label: "已寄出"
  },
  {
    key: "1",
    type: 'info',
    label: "等待开具"
  },
  {
    key: "2",
    type: 'danger',
    label: "开具失败"
  },
  {
    key: "3",
    type: 'success',
    label: "审核通过"
  }
]

// 账户注销状态
export const LogoutStatus = [
  {
    key: "1",
    type: 'info',
    label: "申请中"
  },
  {
    key: "2",
    type: 'danger',
    label: "已通过"
  },
  {
    key: "3",
    type: 'success',
    label: "未通过"
  }
]

//发票类型
export const invoiceClass = [
  {
    label: "发票类型",
    value: "8789324728947"
  },
  {
    label: "增值税普通发票",
    value: "2"
  },
  {
    label: "增值税专用发票",
    value: "1"
  }
]
/** 退款进程 */
export const refundProcessList = [
  {
    key: "1",
    type: 'warning',
    label: "申请中"
  },
  {
    key: "2",
    type: 'danger',
    label: "退款中"
  },
  {
    key: "3",
    type: 'success',
    label: "已完成"
  },
  {
    key: "4",
    type: 'error',
    label: "退款拒绝"
  }
]

/**
 * 账号权限枚举
 */
export const accoutnRoles = [
  { label: "企业用户", value: 2 },
  { label: "运营人员", value: 3 },
  { label: "客服人员", value: 5 },
  { label: "财务人员", value: 4 },
  { label: "系统管理员", value: 1 }
]

/**
 * 账号管理部门枚举
 */
 export const accoutnDutys = [
  { label: "管理部", value: 6 },
  { label: "技术部", value: 2 },
  { label: "市场部", value: 3 },
  { label: "产品部", value: 4 },
  { label: "传媒部", value: 5 },
  { label: "商务部", value: 7 }
]

/**
 * 判断是否为空
 */
export function isNull(val) {
  if (typeof val === 'boolean') {
    return false;
  }
  if (typeof val === 'number') {
    return false;
  }
  if (val instanceof Array) {
    if (val.length === 0) return true;
  } else if (val instanceof Object) {
    if (JSON.stringify(val) === '{}') return true;
  } else {
    if (val === 'null' || val == null || val === 'undefined' || val === undefined || val === '') return true;
    return false;
  }
  return false;
}

export function hkShowLoading(msg) {
  loadingInstance = Loading.service({
    lock: true,
    text: msg || "加载中...",
    spinner: "el-icon-loading",
    background: "rgba(0, 0, 0, 0.7)",
  })
}
export function hkHidLoading() {
  if (loadingInstance) {
    loadingInstance.close()
    loadingInstance = null
  }
}


export function hkCloseMessage() {
  Message.closeAll()
}
export function hkShowText(text) {
  Message({
    message: text,
    type: 'warning'
  })
}

export function hkShowSuccessText(text) {
  Message({
    message: text,
    type: 'success'
  })
}
export function hkShowErrorText(text) {
  Message({
    message: text,
    type: 'error'
  })
}

export function hkGetTimeFmt(time) {
  if (('' + time).length === 10) {
    time = parseInt(time) * 1000
  } else {
    time = +time
  }
  const d = new Date(time)
  return dateFormatCC("YYYY-mm-dd HH:MM:SS", d)
}
/**
 * 时间格式转换
 * @param fmt  "YYYY-mm-dd HH:MM:SS"
 * @param date
 * @returns {*}   dateFormat("YYYY-mm-dd HH:MM:SS", new Date(Number(date)));
 */
export function dateFormatCC(fmt, date) {
  let ret;
  const opt = {
    "Y+": date.getFullYear().toString(),        // 年
    "m+": (date.getMonth() + 1).toString(),     // 月
    "d+": date.getDate().toString(),            // 日
    "H+": date.getHours().toString(),           // 时
    "M+": date.getMinutes().toString(),         // 分
    "S+": date.getSeconds().toString()          // 秒
    // 有其他格式化字符需求可以继续添加，必须转化成字符串
  };
  for (let k in opt) {
    ret = new RegExp("(" + k + ")").exec(fmt);
    if (ret) {
      fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
    }
    ;
  }
  ;
  return fmt;
}
